define(["app","js/services/MuseService",'js/services/MessageBox','js/controllers/car/SelOwner/SelOwnerController'],
    function (app) {
        var deps = ["$scope", "$http", "$rootScope", "$filter", "$state", "$stateParams","MuseService","MessageBox", "$modal"];

        function controller($scope, $http, $rootScope, $filter, $state, $stateParams,MuseService,MessageBox,$modal) {
            $scope.curUser = getSessionJson('curUserObj');

            if(isEmpty($scope.curUser)){
                var url = 'login.html';
                location.replace(url);
            }

            $scope.owner ={};
            $scope.driver = {};
            $scope.type = "";

            $scope.ownerName = "";


            $scope.btnClick = function(type){
                $scope.type = type;
            }

            $scope.checkOwner = function () {

                MuseService.postObj('check/getCheckOwner',$scope.owner).success(
                    function(data){
                        if (data.code == 0) {
                            MessageBox.notify("提交成功！");

                            $scope.curUser.isEffect = "check";
                        } else {
                            MessageBox.error('错误：' + data.msg);
                        }
                    }
                )

            };


            $scope.checkDriver = function () {
                MuseService.postObj('check/getCheckDriver',$scope.driver).success(
                    function(data){
                        if (data.code == 0) {
                            MessageBox.notify("提交成功！");

                            $scope.curUser.isEffect = "check";
                        } else {
                            MessageBox.error('错误：' + data.msg);
                        }
                    }
                )

            };
            // 取消，返回
            $scope.close = function () {
                history.back();
            };



            // 选择新闻
            $scope.getAllOwners = function() {

                var mainTitle = "选择业户";

                /*
                 * 弹窗选择事件
                 */
                var modalInstance = $modal.open({
                    templateUrl : 'views/main/car/selOwner/SelOwner.html',
                    controller : 'SelOwnerController',
                    size:"lg",
                    resolve : {
                        mainTitle: function(){
                            return mainTitle;
                        }
                    },
                    windowClass : 'app-modal-window'
                });

                modalInstance.result.then(function(data) {
                    /*
                     * 组装进入List中  注意  只保存需要的字段
                     */
                    if(data.length>0){
                        //住:讲道理只有一条
                        $scope.ownerName =data[0].company;
                        $scope.driver.ownerId = data[0].id;
                    }

                }, function(data) {
                });
            };



        }

        controller.$inject = deps;
        app.lazy.controller("CheckController", controller);
    });